function test1() {
    //没有bom和dom
    console.log(window);
    console.log(document);
}

//使用require加载文件模块
//读取文件
const fs = require("fs")

function readFileTest() {
    //起始路径为项目根路径
    fs.readFile("./app.js", function (error, data) {
        console.log(data.toString());
        console.log(error);
    })
}


function writeFileTest() {
    fs.writeFile("D:/test.txt", "node测试", function (error) {
        //成功则error为null
        console.log(error);
    })
}


function deleteFileTest() {
    fs.unlink("D:/axis.log", function (error) {
        //成功则error为null
        console.log(error);
    })
}

//加载http模块
const http = require("http")

function httpTest() {
    const server = http.createServer();
    //客户端请求过来,调用回调函数
    server.on("request", function (request, respone) {
        //客户端ip
        const clientIp = request.socket.remoteAddress;
        //客户端端口
        const clientPort = request.socket.remotePort;
        console.log("客户端:", clientIp + ":" + clientPort)


        //根据请求路径调用不同方法
        let url = request.url
        console.log("请求路径", url);
        //解决乱码
        respone.setHeader("Content-Type", "text/html;charset=UTF-8")
        // respone.write("响应数据")
        // //结束请求
        // respone.end();
        if (url === '/') {
            respone.end("/")
        } else if (url === '/test') {
            respone.end("测试")

        } else {
            respone.end("响应数据")
        }
    })
    //端口
    server.listen(9000, function () {
        console.log("服务器启动函数");
    })
}

function httpTest2() {
    http.createServer(function (requset, respone) {
        respone.end("abc")
    }).listen(8080)
}


const os = require("os")

function testOs() {
    console.log(os.cpus());
}


const path = require("path")

function testPath() {
    console.log(path.resolve(""));
}

const test2 = require("./test2")

function testRequire() {
    console.log("test");
    console.log(test2);
    console.log(test2.name);
    console.log(test2.add(1, 2));
}


function testHtmlServer() {
    const server = http.createServer();
    //客户端请求过来,调用回调函数
    server.on("request", function (request, respone) {

        let url = request.url
        //解决乱码

        if (url === '/') {
            respone.end("/")
        } else if (url === '/html') {
            respone.setHeader("Content-Type", "text/html;charset=UTF-8")
            fs.readFile("./page/index.html", function (error, data) {
                if (error) {
                    respone.end("读取失败")
                } else {
                    respone.end(data)
                }
            })
        } else if (url === '/jpg') {
            respone.setHeader("Content-Type", "image/jpeg")
            fs.readFile("./page/douyu.jpg", function (error, data) {
                if (error) {
                    respone.end("读取失败")
                } else {
                    respone.end(data)
                }
            })
        } else {
            fs.readFile(path.join("page",url), function (error, data) {
                if (error) {
                    respone.end("读取失败")
                } else {
                    respone.end(data)
                }
            })
        }
    })
    //端口
    server.listen(9000, function () {
        console.log("服务器启动函数");
    })
}

const template = require("art-template")
// 基于模板名渲染模板
template(filename, data);

// 将模板源代码编译成函数
template.compile(source, options);

// 将模板源代码编译成函数并立刻执行
template.render(source, data, options);

function artTemplateTest() {
    
}